/**
 * Created by superman on 17/2/16.
 * http配置
 */

import axios from 'axios'
import router from "../../routers"; // 引入路由配置
import store from "../../vuex/store";
import Qs from "querystring";
import Vue from "vue";

// axios 配置
axios.defaults.timeout = 5000;
// axios.defaults.baseURL = store.state.path;

// http request 拦截器
axios.interceptors.request.use(
    config => {
        // if (store.state.token) config.headers.Authorization = `token ${store.state.token}`;
        if(config.method=="post"){
           let tempData=Qs.stringify(config.data);
           config.data=tempData;
        }
        return config;
    },
    err => {
        return Promise.reject(err);
    });

// http response 拦截器
axios.interceptors.response.use(
    response => {
        response["body"]=response.data;
        return response;
    },
    error => {
        return Promise.reject(error.response.data)
    });

export default axios;
